<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%String path = request.getContextPath();%>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="<%=path%>/static/layui/css/layui.css" rel="stylesheet">
    <link href="<%=path%>/static/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
</head>

<body>

<form class="layui-form" method="post"  action="<%=path%>/system/dept/save" lay-filter="formDemo" style="margin-top: 40px;width: 600px;" id="data">
    <div class="layui-form-item">
        <label class="layui-form-label">上级部门：</label>
        <div class="layui-input-block">
            <input type="hidden" name="id" id="id" value="<c:if test="${not empty edit}"> ${edit.id}</c:if>">
            <input id="parentId" type="text" readonly="true"   autocomplete="off"
                   value=
                   "<c:choose>
                    <c:when test="${not empty edit}"> ${edit.parent.name}</c:when>
                     <c:when test="${not empty parentAdd}"> ${parentAdd.name}</c:when>
                     <c:when test="${not empty add}"> ${add.name}</c:when>
                    </c:choose>"
                   data-id=
                       "<c:choose>
                            <c:when test="${not empty edit}"> ${edit.parent.id}</c:when>
                             <c:when test="${not empty parentAdd}"> ${parentAdd.id}</c:when>
                             <c:when test="${not empty add}"> ${add.id}</c:when>
                        </c:choose>"
                   class="layui-input" onclick="treeClick()" lay-verify="required">
            <input type="hidden" name="parentId" id="parentIdValue"
                   value="<c:choose>
                    <c:when test="${not empty edit}"> ${edit.parent.id}</c:when>
                     <c:when test="${not empty parentAdd}"> ${parentAdd.id}</c:when>
                     <c:when test="${not empty add}"> ${add.id}</c:when>
                    </c:choose>">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">本部门名：</label>
        <div class="layui-input-block">
            <input type="text" name="name" autocomplete="off"
                   value="<c:if test="${not empty edit}"> ${edit.name}</c:if>"
                   class="layui-input"  lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示顺序：</label>
        <div class="layui-input-block">
            <input type="text" name="sort" autocomplete="off"
                   value="<c:if test="${not empty edit}"> ${edit.sort}</c:if>"
                   class="layui-input" id="parentId2" lay-verify="number">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">描述：</label>
        <div class="layui-input-block">
            <input type="text" name="description" autocomplete="off"
                   value="<c:if test="${not empty edit}"> ${edit.description}</c:if>"
                   class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">负责人：</label>
        <div class="layui-input-block">
    <input id="deptUser" type="text" readonly="true"  autocomplete="off"
           placeholder="<c:if test='${empty edit}'>请选择负责人</c:if>"
           value="<c:if test='${not empty edit}'>${edit.principal.name}</c:if>"
           data-id="<c:if test='${empty edit}'>${edit.principal.id}</c:if>"
           class="layui-input" lay-verify="required" onclick="userClick()">
    <input type="hidden" name="principal.id" id="deptUserValue"
           value="<c:if test="${not empty edit}"> ${edit.principal.id}</c:if>">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态：</label>
        <div class="layui-input-block">
            <input type="checkbox" name="enable" lay-skin="switch" lay-text="正常|禁用" value="0"
             <c:if test="${not empty edit && edit.enable==0}">checked</c:if>
            >
        </div>
    </div>

    <button id="departSubmit" class="layui-btn" lay-filter="formVerify" lay-submit style="display: none">添加</button>

</form>
<script src="<%=path%>/static/layui/layui.all.js"></script>
<script src="<%=path%>/static/js/jquery.min.js?v=2.1.4"></script>
<script src="<%=path%>/static/myjs/MyLayer.js"></script>
<script>
//初始化获得顶级layer
let layer=window.top.layer;
//获得当前iframe索引
let curIframe=layer.getFrameIndex(window.name)
layui.use(['form'], function () {
    let form=layui.form
    form.on('submit(formDemo)', function(data){
        layer.close(curIframe)
    });
})

//点击显示部门树
function treeClick() {
    let res=MyLayer.iframeLayer(layer,"请选择上级部门","<%=path%>/system/department/departmentTree",{
        "确定":function (index) {
                let node = parent['layui-layer-iframe' +index].myTree.getSelectedNodes();
                if (node.length===0){
                    return true;
                }
                let obj=node[0];
                window.$("#parentId").val(obj.name)
                window.$("#parentIdValue").val(obj.id)
        }
    },"small")
}
//点击显示用户表
function userClick() {
    MyLayer.iframeLayer(layer,"请选择负责人","<%=path%>/system/user/userTable",{
        "确定":function (index,layero) {
                let data=parent['layui-layer-iframe' +index].table.checkStatus('userTable').data;
                if (data.length===0){
                    return  true;
                }
                window.$("#deptUser").val(data[0].name)
                window.$("#deptUserValue").val(data[0].id)
        }
    },"small")
}

</script>
</body>

</html>